package com.xnyzc.lhy.common.exception;

import com.xnyzc.lhy.common.penum.EErrorCode;
import org.apache.commons.lang3.ArrayUtils;

public class BusinessSilentException extends RuntimeException {
    private static final long serialVersionUID = -147690664030334727L;
    private Integer code;
    private String description;

    public BusinessSilentException(String message) {
        super(message);
        this.code = 500;
        this.description = message;
    }

    public BusinessSilentException(EErrorCode type, String message) {
        super(message);
        this.code = 500;
        this.description = message;
        this.code = type.getValue();
    }

    public BusinessSilentException(EErrorCode type) {
        this(type, type.getDesc());
    }

    public BusinessSilentException(EErrorCode type, Object... args) {
        this(type, ArrayUtils.isNotEmpty(args) ? String.format(type.getDesc(), args) : type.getDesc());
    }

    public BusinessSilentException(int exceptionCode, String message) {
        super(message);
        this.code = 500;
        this.code = exceptionCode;
        this.description = message;
    }

    public BusinessSilentException(int exceptionCode, String message, Throwable cause) {
        super(message, cause);
        this.code = 500;
        this.code = exceptionCode;
        this.description = message;
    }

    public BusinessSilentException(String message, Throwable cause) {
        super(message, cause);
        this.code = 500;
        this.description = message;
    }

    public int getCode() {
        return this.code;
    }

    public String getDescription() {
        return this.description;
    }
}